<template>
	<view class="container padding-top-sm">
		<view
			class="text-999 radius5 flex justify-between align-center padding bg-white margin-left-sm margin-right-sm margin-bottom-sm">
			<view class="text-13">
				头像
			</view>


			<view class="flex justify-start align-center" @click="upload">
				<image :src="userInfo.userIcon" mode="" class="cu-avatar round lg"></image>
				<view class="cuIcon-right">

				</view>
			</view>
		</view>
		<view class="bg-white radius5 margin-left-sm margin-right-sm margin-bottom-sm">
			<view class="flex justify-between align-center padding" >
				<view class="text-999 text-13">
					昵称
				</view>
				<view class="flex justify-start align-center">
					<input class="text-13 text-181818" @blur='handNickname' style="text-align: right;" v-model="userInfo.nickname">


					<view class="cuIcon-right">

					</view>
				</view>
			</view>
			<view class="flex justify-between align-center padding">
				<view class="text-999 text-13">
					ID
				</view>
				<view class="flex justify-start align-center">
					<view class="text-13 text-181818">
						{{userInfo.id}}
					</view>
					<!-- <view class="cuIcon-right">
						
					</view> -->
				</view>
			</view>
			<view class="flex justify-between align-center padding">
				<view class="text-999 text-13">
					绑定手机号
				</view>
				<view class="flex justify-start align-center">
					<view class="text-13 color">
						{{userInfo.mobile || '暂无'}}
					</view>
					<!-- <view class="cuIcon-right">
						
					</view> -->
				</view>
			</view>
			<view class="flex justify-between align-center padding">
				<view class="text-999 text-13">
					实名认证
				</view>
				<view class="flex justify-start align-center">
					<view class="text-13 text-181818" v-if='userInfo.userIdentityStatus==1'>
						{{userInfo.username}} {{userInfo.userIdCard}}
					</view>
					<view class="text-13 text-181818" v-else @click="toPage('/filePage/pages/real-name/real-name')">
						还未实名认证
					</view>
					<view class="cuIcon-right">

					</view>
				</view>
			</view>
			<!-- <view class="flex justify-between align-center padding"
				@click="toPage('/pagesA/pages/setPassword/setPassword')">
				<view class="text-999 text-13">
					设置余额支付密码
				</view>
				<view class="flex justify-start align-center">
					<view class="text-13 text-181818">

					</view>
					<view class="cuIcon-right">

					</view>
				</view>
			</view> -->
			



		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: this.$config.baseUrl,
				userInfo: {},

			};
		},
		onShow(option) {
			this.getUser()

		},
		methods: {


			// #ifdef  APP-PLUS
			logut() {
				uni.showModal({
					title: '提示',
					content: '你确定要退出吗',
					success: function(res) {
						if (res.confirm) {
							try {
								uni.clearStorageSync();
								uni.clearStorage();
								uni.redirectTo({
									url: '/pages/login/login'
								});
							} catch (e) {
								// error
							}
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			// #endif

			async getUser() {
				const [err, rs] = await this.$get(this.$api.userDetail)
				if (rs) {
					console.log(rs)
					this.userInfo = rs.data;
					uni.setStorageSync('userInfo', rs.data);
					if (rs.data.shopIdApply) {
						uni.setStorageSync('shopIdApply', rs.data.shopIdApply);
					}

					if (rs.data.shopServiceIdApply) {
						uni.setStorageSync('shopServiceIdApply', rs.data.shopServiceIdApply);
					}
					console.log(this.userInfo)
				}
			},
			toPage(url) {
				this.$util.openNewPage(url)
			},
			async handNickname() {
				console.log(111)
				
				const [err, rs] = await this.$jsonPost(this.$api.updateInfo, {
					id: uni.getStorageSync('userId'),
					nickname: this.userInfo.nickname,
				})
				if(rs){
					uni.showToast({
						title:rs.message,
						icon:'none'
					})
				}
			},
			upload() {
				uni.chooseImage({
					success: (chooseImageRes) => {
						console.log(chooseImageRes)
						const tempFilePaths = chooseImageRes.tempFilePaths;
						console.log(chooseImageRes.tempFilePaths)
						uni.uploadFile({
							url: 'https://super.zoyob.com/mall-util/upload/onePic',
							filePath: tempFilePaths[0],
							name: 'file',
							header: {
								userId: uni.getStorageSync('userId'),
								Authorization: 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJ0ZXN0Iiwic2NvcGUiOlsiYWxsIl0sImlkIjoxLCJleHAiOjE2MTA2MTA4OTMsImF1dGhvcml0aWVzIjpbIuWJjeWPsOS8muWRmCJdLCJqdGkiOiJjNTAwYTQzMy04ODVkLTRkOTctYTZjYy1iNDVmYjVkMmVmMzgiLCJjbGllbnRfaWQiOiJwb3J0YWwtYXBwIn0.j7U3u7X37obI98qyvDr8OyCRupkk401kK-7zGuJexT7UKFF8gXTAfWmBjafRMjmuuCqSM-MPLQPQL1Cq8Fzj6bgS6D5Vq9TbVQ43CyE2mLU415CVlyfH0JJ35vRCj_zlgDp7SsW_ichocwfqSo0h0QlaQ6kSsXgktxpMLULIEYI'
							},
							success: (res) => {
								console.log(res.data)
								console.log(2222)
								const data = JSON.parse(res.data)
								this.userInfo.userIcon = data.data
								this.$jsonPost(this.$api.updateInfo, {
									id: uni.getStorageSync('userId'),
									userIcon: data.data
								}).then(res => {
									const [err, rs] = res
									if (rs) {
										console.log(rs)
										this.$util.msg(rs.message)

									}
								})
								console.log(this.coverImage)
							}
						});
					}
				});
			},
		}
	}
</script>

<style lang="scss" scoped>

</style>
